using System;
using System.Windows.Forms;

namespace sy2_11
{
    public partial class Form1 : Form
    {
        int[] num;
        int[] prime;

        public Form1()
        {
            InitializeComponent();
        }

        private bool IsPrime(int n)
        {
            if (n <= 1) return false;
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0) return false;
            }
            return true;
        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            int count = int.Parse(txtCount.Text);
            int min = int.Parse(txtMin.Text);
            int max = int.Parse(txtMax.Text);

            num = new int[count];
            prime = new int[count];
            int primeIndex = 0;

            Random rnd = new Random();
            for (int i = 0; i < count; i++)
            {
                num[i] = rnd.Next(min, max + 1);
                if (IsPrime(num[i]))
                {
                    prime[primeIndex] = num[i];
                    primeIndex++;
                }
            }

            txtNum.Text = string.Join(Environment.NewLine, num);

            btnPrime.Enabled = true;

            Array.Resize(ref prime, primeIndex);
        }

        private void btnPrime_Click(object sender, EventArgs e)
        {
            txtPrime.Text = string.Join(Environment.NewLine, prime);
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }
    }
}